package com.yiren.backstage.config.api;

import android.content.Context;

import com.google.gson.Gson;
import com.yiren.backstage.config.bean.device.CarSignalConfigBean;
import com.yiren.backstage.config.bean.device.DeviceStudyConfigBean;
import com.yiren.backstage.config.bean.device.PracticeCarCheckConfigBean;
import com.yiren.backstage.config.bean.device.SignalSourceConfigBean;
import com.yiren.backstage.config.bean.device.StationParamConfigBean;
import com.yiren.backstage.config.bean.device.UserParamConfigBean;
import com.yiren.backstage.config.bean.device.UserRiskConfigBean;
import com.yiren.backstage.config.enums.ConfigNameEnum;
import com.yiren.backstage.config.services.IConfigService;
import com.yiren.backstage.config.services.impl.ConfigServiceImpl;

/**
 * @author xiaozan
 * @Description 保存参数配置 api
 * @Date 2022/3/18
 */
public class SaveConfigApi {

    private static IConfigService iConfigService = new ConfigServiceImpl();
    private static Gson gson = new Gson();
    private static final String split = "#";

//    <!-----------------------------------------保存设备参数配置----------------------------------------->/

    /**
     * 根据配置名称加载参数
     *
     * @param context
     * @param configName
     * @param value
     */
    public static void saveConfig(Context context, String configName, Object value) {
        iConfigService.putSharedPreferences(context, configName, value);
    }

    /**
     * 保存车辆信号配置(正反转) 对象
     */
    public static void saveCarSignalConfig(Context context, CarSignalConfigBean carSignalConfigBean) {
        iConfigService.putSharedPreferences(context, ConfigNameEnum.CAR_SIGNAL_CONFIG.toString(), gson.toJson(carSignalConfigBean));
    }

    /**
     * 保存设备学习数据配置参数
     */
    public static void saveDeviceStudyConfig(Context context, DeviceStudyConfigBean deviceStudyConfigBean) {
        iConfigService.putSharedPreferences(context, ConfigNameEnum.DEVICE_STUDY_CONFIG.toString(), gson.toJson(deviceStudyConfigBean));
    }

    /**
     * 保存练车检测参数配置
     */
    public static void savePracticeCarCheckConfig(Context context, PracticeCarCheckConfigBean practiceCarCheckConfigBean) {
        iConfigService.putSharedPreferences(context, ConfigNameEnum.PRACTICE_CAR_CHECK_CONFIG.toString(), gson.toJson(practiceCarCheckConfigBean));
    }

    /**
     * 保存信号源配置参数
     */
    public static void saveSignalSourceConfig(Context context, SignalSourceConfigBean signalSourceConfigBean) {
        iConfigService.putSharedPreferences(context, ConfigNameEnum.SIGNAL_SOURCE_CONFIG.toString(), gson.toJson(signalSourceConfigBean));
    }

    /**
     * 保存固定站移动站主机盒参数配置
     */
    public static void saveStationParamConfig(Context context, StationParamConfigBean stationParamConfigBean) {
        iConfigService.putSharedPreferences(context, ConfigNameEnum.STATION_PARAM_CONFIG.toString(), gson.toJson(stationParamConfigBean));
    }

    /**
     * 保存用户参数配置
     */
    public static void saveUserParamConfig(Context context, UserParamConfigBean userParamConfigBean) {
        iConfigService.putSharedPreferences(context, ConfigNameEnum.USER_PARAM_CONFIG.toString(), gson.toJson(userParamConfigBean));
    }

    /**
     * 保存用户参数配置
     */
    public static void saveUserRiskConfig(Context context, UserRiskConfigBean userRiskConfigBean) {
        UserParamConfigBean userParamConfig = LoadConfigApi.loadUserParamConfig(context);
        if (null != userParamConfig.getUserInfo()) {
            iConfigService.putSharedPreferences(context, ConfigNameEnum.USER_RISK_CONFIG.toString() + split + userParamConfig.getUserInfo().getId(), gson.toJson(userRiskConfigBean));
        }
    }

}